// 用户个人中心模块
import { userAccountLogin } from '@/api/user'
// 用户状态
export default {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      account: '',
      nickname: '',
      avatar: '',
      token: '',
      mobile: ''
    }
  }
  ),
  mutations: {
    // 获取个人信息
    setUserInfo (state, info) {
      state.profile = info
    },
    // 清除个人信息
    removeUserInfo (state) {
      state.profile = {
        id: '',
        account: '',
        nickname: '',
        avatar: '',
        token: '',
        mobile: ''
      }
    }
  },
  actions: {
    // 异步获取个人信息
    async asyncSetUserInfo (store, info) {
      const res = await userAccountLogin(info)
      store.commit('setUserInfo', res.result)
      return new Promise((resolve, reject) => {
        resolve(res.result)
      })
    }
  }
}
